package com.htt.bms.controller.system;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.htt.bms.domain.sys.SysUser;
import com.htt.bms.domain.sys.dto.SysUserDto;
import com.htt.bms.service.system.SysUserService;
import com.htt.bms.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 侯婷婷
 * @version 1.0
 * @description 用户controller
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(value = "user", tags = "用户")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    /**
     * 测试controller能否运行
     * @return
     */
    @GetMapping("/hi")
    @ApiOperation(value = "测试运行")
    public String hi(){
        return "hi";
    }

    @GetMapping("/one")
    @ApiOperation(value = "查询单个")
    public SysUser selectOne(){
        return sysUserService.getBaseMapper()
                .selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, "admin"));
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询所有")
    public List<SysUser> selectAll(){
        return sysUserService.getBaseMapper()
                .selectList(Wrappers.<SysUser>lambdaQuery());
    }


    /**
     * 获取用户列表
     * @param dto 数据传输对象
     * @return
     */
    @ApiOperation(value = "用户列表")
    @PostMapping("/list")
    public Result<List<SysUser>> list(SysUserDto dto){
        return Result.success(sysUserService.list(dto));
    }



}
